<template>
  <view>
    <tm-sheet
      :margin="[20]"
      :round="3"
      :shadow="2"
      v-for="(item, index) in props.list"
      :key="index"
      @click="toDetail(item)"
    >
      <view class="flex">
        <view class="icon-img">
          <img
            src="../../../static/add-icon.png"
            alt=""
            class="icon-img"
            v-if="item.metadata.typeName == '加用户'"
          />
          <img
            src="../../../static/work-icon.png"
            alt=""
            class="icon-img"
            v-else
          />
        </view>
        <view class="m-l-15 flex-list">
          <tm-text
            _class="text-overflow-1 text-weight-b m-b-3"
            parentClass="wd200"
            :label="item.name"
          ></tm-text>
          <view class="flex m-b-3 tag-position">
            <tm-tag
              v-for="tag in item.groupTags"
              :key="tag"
              outlined
              :shadow="0"
              color="#366EF4"
              :margin="[5, 10]"
              font-color="#366EF4"
              border-color="#366EF4"
              size="xs"
              :label="tag"
            ></tm-tag>
          </view>
          <tm-text
            :font-size="24"
            color="grey"
            _class="text-overflow-1"
            :label="item.remark || item.code"
          ></tm-text>
        </view>
        <view class="rg-time">
          <tm-text
            :font-size="24"
            color="grey"
            :label="showChatTime(item.updateTime)"
          ></tm-text>
        </view>
      </view>
    </tm-sheet>
  </view>
</template>
<script lang="ts" setup>
import { IFile } from '@/ts/core'
import { showChatTime } from '@/utils/tools'
import { ref } from 'vue'

type Props = {
  list: IFile[] // 卡片正文列表
  tagActive: string //当前选择的tab选项卡
}

const props = defineProps<Props>()
/** 进入审批页面 */
const jumpData = ref('')
async function toDetail(data: any) {
  if (props.tagActive === 'commons') {
    jumpData.value = data
    // uni.navigateTo({
    //   url: '/pages/work/apply',
    //   success: res => {
    //     res.eventChannel.emit('workDetail', data)
    //   }
    // })
    uni.navigateTo({
      url: '/pages/work/webview',
      success: res => {
        res.eventChannel.emit('workInfo', data)
      }
    })

    return
  }
  if (['加用户'].includes(data.metadata.typeName)) {
    uni.navigateTo({
      url: '/pages/work/detail?item=' + data.taskdata.taskType,
      success: res => {
        res.eventChannel.emit('workDetail', data.taskdata)
      }
    })
  } else {
    switch (data.typeName) {
      case '办事':
      case '子流程':
        return console.log('aaaasss', data.directory.resource.formColl)
      case '事项':
        {
          const params = {
            taskId: data.taskdata.id,
            instanceId: data.taskdata.instanceId,
            belongId: data.taskdata.belongId,
            taskType: data.taskdata.taskType
          }
          uni.navigateTo({
            url: '/pages/work/detail?item=' + JSON.stringify(params)
          })
        }
        break
    }
  }
}
</script>
<style>
.icon-img {
  width: 50px;
  height: 50px;
}
.tag-position {
  display: flex;
  flex-wrap: wrap;
}
</style>
